package com.gaoyi.crm.fragment;

import android.os.Bundle;
import android.widget.RadioGroup;

import androidx.activity.result.ActivityResult;

import com.gaoyi.crm.R;
import com.gaoyi.crm.constant.BundleKeyName;
import com.gaoyi.crm.databinding.FragmentEditRecordBinding;
import com.gaoyi.crm.db.entity.PmnWithList;
import com.gaoyi.crm.fragment.base.BaseParentFragment;
import com.gaoyi.crm.vm.EditRecordViewModel;

import java.util.Map;

public class EditRecordFragment extends BaseParentFragment<FragmentEditRecordBinding, EditRecordViewModel, PmnWithList> {

    public static final String ID = "id";

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_edit_record;
    }

    @Override
    protected int getFragmentId() {
        return R.id.edit_fragment;
    }

    @Override
    protected void initView() {
        mBinding.rgMenu.setOnCheckedChangeListener(new MyOnCheckChangeListener());
        mBinding.rgMenu.check(R.id.rb_cus_info);
        mBinding.tvEditBack.setOnClickListener(view -> mContext.onBackPressed());
    }

    private class MyOnCheckChangeListener implements RadioGroup.OnCheckedChangeListener {

        @Override
        public void onCheckedChanged(RadioGroup radioGroup, int i) {
            if (i == R.id.rb_cus_info) {
                showFragment(0);
            } else {
                showFragment(1);
            }
        }
    }

    @Override
    protected void initFragment() {
        Bundle arguments = getArguments();
        if (arguments == null) {
            mContext.onBackPressed();
            return;
        }
        String id = arguments.getString(ID);
        Bundle bundle = new Bundle();
        bundle.putBoolean(BundleKeyName.IS_EDIT, true);
        bundle.putString(BundleKeyName.ID, id);
        NewPromotionFragment newPromotionFragment = new NewPromotionFragment();
        newPromotionFragment.setArguments(bundle);
        ScannedListFragment scannedListFragment = new ScannedListFragment();
        scannedListFragment.setArguments(bundle);
        setFragment(newPromotionFragment);
        setFragment(scannedListFragment);
    }

    @Override
    protected void initLiveData() {
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void onRequestPermissionsResult(Map<String, Boolean> result) {

    }

    @Override
    protected void onActivityResult(int requestCode, ActivityResult result) {

    }
}